from typing import Callable
from Board import Board


from Frame import Frame

class TemplateSolver:
    """
    模板类, 用于生成下一步步伐, 应该被继承
    """
    def __init__(self, solve_func: Callable[[Frame], tuple]) -> None:
        """传入一个可调用的算法函数

        Args:
            solve_func (Callable[[Frame], tuple]): 算法函数
        """
        self.solver_func = solve_func
        # reference_player 在帮哪个玩家下棋, 需要被子类重写并被赋值, 一被重写就不应改变, 当然有的也可以不用
        self.reference_player = -1
        
    
    def solve(self, frame: Frame):
        return self.solver_func(frame)
    

    def evaluate(self, frame: Frame, color: int):
        """
        评估当前棋局, 虽然当前传入了frame, 但并没有用到frame的current_round, 真正参与评分的color形参, color代表的含义是当前是谁的回合
        """
        cScore = 20
        cThree = 15
        cTwo = 1

        score = 0
        if self.reference_player == frame.red_player:
            score = cScore * frame.red_score - cScore * frame.blue_score
        else:
            score = cScore * frame.blue_score - cScore * frame.red_score
        if self.reference_player == color:
            score += cThree * frame.current_board.get_box_count(3) - cTwo * frame.current_board.get_box_count(2)
        else:
            score -= cThree * frame.current_board.get_box_count(3) - cTwo * frame.current_board.get_box_count(2)
        return score
    
